<template>
  <div class="container">
    <div>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="查询方式：">
              <el-select
                style="width: 180px"
                v-model="form.queryType"
                placeholder="请选择"
                @change="changeHandler"
              >
                <el-option
                  v-for="item in form.queryTypeList"
                  :key="item.index"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="选择日期：">
              <!-- <el-radio v-model="form.radioData" label="日">按日期：</el-radio> -->
              <!-- <span>查询日期：</span>
              <el-radio-group v-model="form.radioData" @change="changeHandler">
                <el-radio label="日">日</el-radio>
                <el-radio label="月">月</el-radio>
              </el-radio-group> -->
              <el-date-picker
                v-model="form.valueDay"
                :type="form.typeDatePicker"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
                style="width: 180px"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="车辆类型：">
              <el-select
                style="width: 180px"
                v-model="cartypestr"
                placeholder="请选择车辆类型"
              >
                <el-option
                  v-for="(item, index) in cartypelist"
                  :value="item.cartype"
                  :label="item.cartype"
                  :key="index"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col> 
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float:left">
            <el-button size="mini" type="primary" @click="getlistdata">查 询</el-button>
            <el-button size="mini" type="success" @click="exportExcel">导 出</el-button>
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
      :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)"
      highlight-current-row
    >
      <el-table-column prop="车辆名称" label="车辆名称" align="center"></el-table-column>
      <el-table-column prop="车辆类型" label="车辆类型" align="center"></el-table-column>
      <el-table-column prop="作业距离" label="作业距离（米）"></el-table-column>
      <el-table-column prop="清扫面积" label="清扫面积(平方米)"></el-table-column>
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      currentPage: 1, //初始页
      pageSize: 15,    //    每页的数据
      form: {
        radioData: '日',
        valueDay: formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        valueMonth: '',
        valueYear: '',
        queryType: 1,
        queryTypeList: [{
          value: 1,
          label: '按日期查询'
        }, {
          value: 2,
          label: '按月份查询'
        }, {
          value: 3,
          label: '按年份查询'
        }],
        typeDatePicker: 'date'
      },
      tableData: [],
      originalData: [],
      exportExcelData: [],
      cartypestr:'洗扫',
      cartypelist:[{"cartype":"洗扫"},{"cartype":"机扫"},{"cartype":"洒水"},{"cartype":"冲洗"}],
    }
  },
  created () {
    this.getlistdata();
  },
  methods: {
    async getlistdata () {
      // this.tableData=[];
      // this.exportExcelData = [];
      // var date = ''
      // var timetype=''
      // if (this.form.radioData === '日') {
      //   date = this.form.valueDay
      //   timetype = 1 
      // }
      // if (this.form.radioData === '月') {
      //   date = this.form.valueMonth+'-01'
      //   timetype = 2
      // }
      // if (this.form.radioData === '年') {
      //   date = this.form.valueYear
      //   timetype = 3
      // }
      this.currentPage = 1;
      var url = 'Vehicle/GetExcelCarWorkArea?WORKDATE=' + this.form.valueDay + '&CLIENT_NO=' + localStorage.getItem('CLIENT_NO')+ '&timetype=' + 
      this.form.queryType+ '&selecttype=1' +  '&cartype=' + this.cartypestr
      
      const { data } = await this.$Http.get(url)
      data.splice(0,1)
      this.exportExcelData = data
      this.tableData = data
    },
    changeHandler (value) {
      switch (this.form.queryType) {
        case 1:
          this.form.typeDatePicker = 'date'
          break;
        case 2:
          this.form.typeDatePicker = 'month'
          break;
        case 3:
          this.form.typeDatePicker = 'year'
          break;
        default:
          break;
      }
      this.form.valueDay = ''
    },
    // 导出Excel
    exportExcel () {
      let excelName = '车辆作业面积统计表'
      const tHeader = ['车辆名称','车辆类型', '作业距离（米）', '清扫面积（平方米）']
      const filterVal = ['车辆名称','车辆类型', '作业距离',  '清扫面积']
      export2Excel(tHeader, filterVal, this.exportExcelData, excelName)
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
    height: 40px;
}
</style>